﻿using System;
using System.Collections;
using System.Linq;
using System.Text;

namespace CompaniDirectorWokers
{
    class Program
    {
        static void Main(string[] args)
        {
            WokerClass[] wokers = new WokerClass[3];
            wokers[0] = new WokerClass("Ivanov", 22, "Brest", Function.Helper);
            wokers[1] = new WokerClass("Petrov", 20, "Gomel", Function.Secretary);
            wokers[2] = new WokerClass("Sidorov", 21, "Minsk", Function.Woker);

            DirectorClass _director = new DirectorClass("Sentjur", 21, "Minsk", Function.Director, wokers);
            _director.LoockAtWokers();
            Console.WriteLine();

            WokersClass _wokers = new WokersClass(wokers);
            foreach (WokerClass i in _wokers)
            {
                Console.WriteLine("кто директор? - {0}", i._director);
            }
            Console.ReadLine();
        }
    }

    /// <summary>
    /// Задание класса Директор
    /// </summary>
    public class DirectorClass
    {
        private Int32 scetchik = 0;
        public InfoClass InfoDirector;
        public WokersClass _wokers;

        public DirectorClass(String _name, Int32 _age, String _city, Function _f, WokerClass[] wokers)
        {
            scetchik++;
            if (scetchik > 1) throw new Exception("превышено число директоров!!!");
            InfoDirector = new InfoClass(_name, _age, _city, _f);
            InfoDirector.Doljnoct = Function.Director;
            _wokers = new WokersClass(wokers);
        }

        public void LoockAtWokers()
        {
            foreach (WokerClass i in _wokers)
            {
                if (i.InfoWoker.Doljnoct == Function.Secretary) i._director = this;
                Console.WriteLine("рабочий по имени {0} занимает должность {1}", i.InfoWoker.Name, i.InfoWoker.Doljnoct.ToString());
            }
        }
    }

    /// <summary>
    /// Задание класса Рабочий
    /// </summary>
    public class WokerClass
    {
        public InfoClass InfoWoker;
        public DirectorClass _director;

        public WokerClass(String _name, Int32 _age, String _city, Function _f)
        {
            InfoWoker = new InfoClass(_name, _age, _city, _f);
            if (InfoWoker.Doljnoct == Function.Director) throw new Exception("недопустимо рабочему присваивать статус директора!!!");
        }
    }

    /// <summary>
    /// Задание класса Рабочих
    /// </summary>
    public class WokersClass : IEnumerable
    {
        private WokerClass[] _wokers;

        public WokersClass(WokerClass[] wokers)
        {
            _wokers = wokers;
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        public IEnumerator GetEnumerator()
        {
            foreach (var i in _wokers)
            {
                yield return i;
            }
        }
    }

    /// <summary>
    /// Задание класса, хранящего информацию о сотрудниках
    /// </summary>
    public class InfoClass
    {
        public String Name { get; set; }
        public Int32 Age { get; set; }
        public String City { get; set; }
        public Function Doljnoct { get; set; }

        public InfoClass(String _name, Int32 _age, String _city, Function _f)
        {
            Name = _name;
            Age = _age;
            City = _city;
            Doljnoct = _f;
        }
    }

    public enum Function { Director, Secretary, Woker, Helper}
}
